package com.liu.service.service.impl;

import com.liu.common.commons.PageVo;
import com.liu.service.dao.SysResMapper;
import com.liu.service.entity.SysRes;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liu.service.service.ISysResService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.poi.ss.formula.functions.T;

/**
 * <p>
 * 资源表 服务实现类
 * </p>
 *
 * @author lxh
 * @since 2020-11-29
 */
@Service
public class SysResServiceImpl extends ServiceImpl<SysResMapper, SysRes> implements ISysResService {

    @Autowired
    private SysResMapper baseMapper;

    @Override
    public IPage<SysRes> findListByPage(PageVo< T> page){
           Page<SysRes> pageInfo = new Page<>(page.getCurrent(), page.getSize());
       QueryWrapper<SysRes> wrapper = new QueryWrapper<>();
        //todo:构造查询参数 根据业务添加

       if (StringUtils.isNotBlank(page.getSortField())){
           wrapper.orderBy(true,0!=page.getDirection() ,page.getSortField());
       }else {
           wrapper.orderByDesc("id");
       }
        IPage<SysRes> iPage = baseMapper.selectPage(pageInfo, wrapper);
        return iPage;
    }

    @Override
    public Boolean add(SysRes sysRes){
    sysRes.setId(IdWorker.getId());
        baseMapper.insert(sysRes);
        return true;
    }

    @Override
    public Boolean delete(Long id){
        baseMapper.deleteById(id);
        return true;
    }

    @Override
    public Boolean updateData(SysRes sysRes){
        baseMapper.updateById(sysRes);
        return true;
    }

    @Override
    public SysRes findById(Long id){
        SysRes sysRes = baseMapper.selectById(id);
        return sysRes;
    }
}
